window.onload = function (){
    showClassData();
}

function showClassData(){
    axios.get("/class/findAll").then(resp =>{
        var info = resp.data;

        if (info === "noland"){
            location.href="/login.html?errorInfo=noland";
        }
        var str="";
        info.forEach(n =>{
            str+=`<tr><td class="alt">${n.className}</td>
                      <td class="alt">${n.date}</td>
                      <td class="alt">${n.teacher}</td>
                    <td class="alt"><input class="button" type="button" value="删除班级" onclick="delClass(${n.id})">
                    </td></tr>`;
        })
        $("data").innerHTML=str;
    })
}

function showAddClass(){
    $("addClass").style.visibility="visible";
}

function backToClassMain(){
    $("addClass").style.visibility="hidden";
}

function addNewClass1(){
    axios.get("/class/add",{
        params:{
            className:$("addClassName").value,
            teacher:$("addClassTeacher").value,
            date:$("addClassDay").value
        }
    }).then(resp =>{
        var info=resp.data;
        if (info == "ok"){
            backToClassMain()
            showClassData();
        }
    })
}

function delClass(id){
    axios.get("/class/del",{
        params: {
            id
        }
    }).then(resp =>{
        var info = resp.data;
        if (info == "ok"){
            backToClassMain()
            showClassData();
        }
    })
}